package lumingweihua.future.cn.lumingweihua.ui.order;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import butterknife.BindView;
import butterknife.ButterKnife;
import lumingweihua.future.cn.lumingweihua.R;
import lumingweihua.future.cn.lumingweihua.ui.BaseCompatActivity;

/**
 * Created by z1986 on 2018/3/16.
 */

public class OrderDetailActivity extends BaseCompatActivity {
    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);
        ButterKnife.bind(this);
        final String good_num = getIntent().getStringExtra(_EXTRA_String_ID);
        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            String[] names = new String[]{"运输信息", "货运详情"};
            Fragment[] fragments = new Fragment[2];

            @Override
            public Fragment getItem(int position) {
                if (position == 0) {
                    if (fragments[position] == null) {
                        fragments[position] = new OrderGoodsInfoFragment();
                    }
                    ((OrderGoodsInfoFragment) fragments[position]).setId(good_num);
                } else {
                    if (fragments[position] == null) {
                        fragments[position] = new SupplyGoodsInfoFragment();
                    }
                    ((SupplyGoodsInfoFragment) fragments[position]).setId(good_num);
                }
                return fragments[position];
            }

            @Override
            public int getCount() {
                return 2;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return names[position];
            }
        });
        tabLayout.setupWithViewPager(viewPager);
    }
}
